package com.example.module_devices

import androidx.recyclerview.widget.LinearLayoutManager
import com.alibaba.android.arouter.facade.annotation.Route
import com.alibaba.android.arouter.launcher.ARouter
import com.example.module_devices.databinding.ActivityDevicesBinding
import com.yuwei.base.BaseActivity
import com.yuwei.common.path.RouterPath
import dagger.hilt.android.AndroidEntryPoint

@Route(path = RouterPath.DEVICES)
@AndroidEntryPoint
class DevicesActivity : BaseActivity<ActivityDevicesBinding, DeviceViewModel>() {
    lateinit var deviceAdapter: DeviceAdapter
    override fun initView() {
        deviceAdapter = DeviceAdapter()
        binding.deviceRv.adapter = deviceAdapter
        binding.deviceRv.layoutManager=LinearLayoutManager(this)
        vm.getDeviceList()
        binding.deviceBack.setOnClickListener {
            finish()
        }
        binding.deviceMore.setOnClickListener {
            ARouter.getInstance().build(RouterPath.ADD_DEVICES).navigation()
        }
    }

    override fun initData() {
        vm.getDeviceSuccess.observe(this){
            deviceAdapter.data.clear()
            deviceAdapter.data.addAll(it)
            deviceAdapter.data.reverse()
            deviceAdapter.notifyDataSetChanged()
        }
    }

    override fun onResume() {
        super.onResume()
        vm.getDeviceList()
    }
}